package com.web.netalbum.util;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class MD5Util {
	public static String md5Encode(String info){
		byte[] bytes=null;
		 char hexDigits[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
				    'a', 'b', 'c', 'd', 'e', 'f' };
		try {
			MessageDigest digest=MessageDigest.getInstance("MD5");
			bytes=info.getBytes();
			digest.update(bytes);
			bytes=digest.digest();
			 char newStr[] = new char[32];
			for (int i = 0; i < bytes.length; i++) {
				 byte tmp = bytes[i];
                newStr[2*i] = hexDigits[tmp >>> 4 & 0xf];
                newStr[2*i+1] = hexDigits[tmp & 0xf];
			}
			return new String(newStr);
		} catch (NoSuchAlgorithmException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}
}
